package ooday04homework;

public class PolymorphicDemo {

    public static void main(String[] args) {
        Animal[] animals = new Animal[3];
        animals[0] = new Dog("狗小黄",2,"黄色");//向上造型
        animals[1] = new Chick("鸡小花",1,"白色");
        animals[2] = new Fish("鱼花花",1,"白色");
        //System.out.println(animals[0].name);
        for (int i = 0; i < animals.length ; i++) {
            System.out.println("=======================================");
            System.out.println(animals[i].name);
            animals[i].eat();
            animals[i].drink();

            if (animals[i] instanceof Dog){
                Dog dog = (Dog)animals[i];
                dog.lookHome();
                //((Dog)animals[i]).lookHome();
            }
            if (animals[i] instanceof Chick){
                Chick chick = (Chick)animals[i];
                chick.layEggs();
            }
            if(animals[i] instanceof Swim){
                Swim swim = (Swim)animals[i];
                swim.swim();
            }
            Master master = new Master();
            System.out.print("主人喂食:"+animals[i].name+",");
            master.feed(animals[i]);

            System.out.println("=======================================");
        }

    }
}
